﻿#include "widget.h"
#include "ui_widget.h"
#include "filetrans_server.h"
#include "filetrans_socket.h"
#include "mediaserver.h"
#include "mediaimgserver.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    setWindowTitle("服务器");
    loadConfig();
    MyServer::getInstance().listen(QHostAddress(m_ip),m_port);
    if(FileTrans::getInstance().listen(QHostAddress(m_ip),10087))//文件传输端口
    {
        qDebug()<<"filetrans listen success"<<endl;
    }
    if(MediaServer::getInstance().listen(QHostAddress(m_ip),10088))//文件传输端口
    {
        qDebug()<<"mediasound listen success"<<endl;
    }
    if(MediaImgServer::getInstance().listen(QHostAddress(m_ip),10089))//文件传输端口
    {
        qDebug()<<"mediaimg listen success"<<endl;
    }
}

Widget::~Widget()
{
    delete ui;
}

void Widget::loadConfig()
{
    QFile file(":/1.txt");
    if(false==file.open(QIODevice::ReadOnly))
    {
        QMessageBox::warning(this,"警告","打开文件失败");
    }
    QByteArray ba = file.readAll();
    file.close();
    QString str(ba.toStdString().c_str());
    QStringList list = str.split("\r\n");
    m_ip = list.at(0);
    m_port = list.at(1).toUInt();
    qDebug()<<m_ip<<m_port;
}



